#include <stdio.h>
#include <unistd.h>

#include "ohos_init.h"
#include "cmsis_os2.h"
#include "st7735s.h"

#include "lvgl.h"
#include "lv_port_disp_template.h"

void lv_ex_label(void)
{
	lv_obj_t* btn = lv_btn_create(lv_scr_act()); 
	lv_obj_set_pos(btn, 0, 0);			//x,y
	lv_obj_set_size(btn, 60, 30);
	lv_obj_t* label = lv_label_create(btn);
    lv_label_set_text(label, "FSR");
    lv_obj_center(label);
}

static void ST7735S_Task(void* arg)
{
    (void) arg;
    lcdInit();
    lcdClear(0xFFFF);
    lv_init();  //lvgl初始化
    lv_port_disp_init();    //lvgl屏幕驱动初始化
    lv_ex_label();  //按钮组件
    while (1)
    {

        lv_tick_inc(5); //计时器
		lv_task_handler();  //lvgl执行函数
		usleep(5000);	
	} 
    // LCD_DisplayOn();
    return 0;
}

static void ST7735S_Entry(void)
{
    osThreadAttr_t attr;


    attr.name = "ST7735S_Task";
    attr.attr_bits = 0U;
    attr.cb_mem = NULL;
    attr.cb_size = 0U;
    attr.stack_mem = NULL;
    attr.stack_size = 1024 * 20;
    attr.priority = osPriorityNormal;

    if (osThreadNew(ST7735S_Task, NULL, &attr) == NULL) {
        printf("[ST7735S_Task] Falied to create ST7735S_Task!\n");
    }
}

SYS_RUN(ST7735S_Entry);
